//
//  BaseViewController.m
//  CocoaPodsTest
//
//  Created by Box on 14-5-8.
//  Copyright (c) 2014年 Box. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (id)init
{
    self = [super init];
    if (self) {
        // Custom initializationjabber.org
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationController setNavigationBarHidden:YES];
    version = [[[UIDevice currentDevice] systemVersion] floatValue];//判断当前系统的版本号
    
    [self.navigationController setNavigationBarHidden:YES];
    
    self.rigthButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.backgroundColor = [UIColor clearColor];
    self.titleLab.font = [UIFont systemFontOfSize:20];
    if (version>=7) {
        CGFloat navHeight = 64;
        _navBG = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, navHeight)];
        
        _bgImageView= [[UIImageView alloc]initWithFrame:_navBG.bounds];
        _bgImageView.backgroundColor = [UIColor colorWithRed:0.98 green:0.57 blue:0.27 alpha:1];
        [_navBG addSubview:_bgImageView];
        
        [self.view insertSubview:_navBG atIndex:10000000];
        self.rigthButton.titleLabel.font = [UIFont systemFontOfSize:14];
        self.titleLab.textColor = [UIColor blackColor];
        self.titleLab.textAlignment = NSTextAlignmentCenter;
        self.titleLab.font = [UIFont systemFontOfSize:18];
        
        self.leftButton.frame = CGRectMake(0, 20, 60, 44);
        self.rigthButton.frame = CGRectMake(260, 20, 60, 44);
        self.titleLab.frame = CGRectMake(60, 27, 200, 30);
        [_navBG addSubview:_leftButton];
        [_navBG addSubview:_rigthButton];
        [_navBG addSubview:_titleLab];
    } else {
        
        
        _navBG = [[UIView alloc]initWithFrame:CGRectMake(0, -20, 320, 44)];
        [self.view addSubview:_navBG];
        
//        navBG.backgroundColor = [UIColor redColor];
        _bgImageView= [[UIImageView alloc]initWithFrame:_navBG.bounds];
        _bgImageView.backgroundColor = [UIColor colorWithRed:0.87 green:0.87 blue:0.87 alpha:1];
        [_navBG addSubview:_bgImageView];
        
        [self.view insertSubview:_navBG atIndex:10000000];
        self.leftButton.frame = CGRectMake(0, 0, 60, 44);
        self.rigthButton.frame = CGRectMake(260, 0, 60, 44);
        self.titleLab.frame = CGRectMake(60, 7, 200, 30);
        self.titleLab.textAlignment = NSTextAlignmentCenter;
        [_navBG addSubview:_leftButton];
        [_navBG addSubview:_rigthButton];
        [_navBG addSubview:_titleLab];
    }
    
    
}
////将上面的标题居中布局
//- (void)navigationStyle:(NSString *)str {
//    UIFont *font = [UIFont systemFontOfSize:22];
//    CGSize size = [self theWordSize:str andFont:font];
//    labTitle.frame = CGRectMake((Kwidth - size.width)/2, (44 - size.height)/2, size.width, size.height);
//    labTitle.text = str;
//    labTitle.font = font;
//}

//返回字体的大小
- (CGSize)theWordSize:(NSString *)str andFont:(UIFont *)font {
    
    CGSize size;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil];
        size =[str boundingRectWithSize:CGSizeMake(320, 1000.0f) options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:tdic context:nil].size;
    } else {
        //        size = [str sizeWithFont:font constrainedToSize:CGSizeMake(320, 1000.0f) lineBreakMode:NSLineBreakByCharWrapping];//ios7以上已经摒弃的这个方法
    }
    return  size;
}

- (CGSize)theWordSize:(NSString *)str andFont:(UIFont *)font andCGSize:(CGSize)sizeT {
    CGSize size;
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil];
        size =[str boundingRectWithSize:sizeT options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:tdic context:nil].size;
    } else {
        //        size = [str sizeWithFont:font constrainedToSize:CGSizeMake(320, 1000.0f) lineBreakMode:NSLineBreakByCharWrapping];//ios7以上已经摒弃的这个方法
    }
    return size;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}


@end
